#!/usr/bin/python
# -*- coding: utf-8 -*-

from datetime import datetime, timedelta, date
def calcTimeToTSN():
	def days_to_hr(days):
		if days == 1: return u'день'
		elif days in (2,3,4): return u'дня'
		else: return u'дней'
	def hours_to_hr(hours):
		if hours == 1: return u'час'
		elif hours in (2,3,4): return u'часа'
		else: return u'часов'
	def minutes_to_hr(minutes):
		if minutes == (1, 21, 31, 41, 51): return u'минута'
		elif minutes in (2,3,4) or minutes>20 and minutes%10 in (2,3,4): return u'минуты'
		else: return u'минут'

	now = datetime.now()
	weekday = now.weekday()
	thusday_num = 3

	SECONDS_IN_DAY = 60*60*24
	SECONDS_IN_HOUR = 60*60
	SECOUND_IN_MINUTE = 60

	days = thusday_num-weekday
	to_thuesday = days if days>0 else 7+days
	TSNDateTime = datetime(now.year, now.month, now.day, 23, 0)+timedelta(days=to_thuesday)
	timeLast = TSNDateTime - now
	secondsLast = timeLast.seconds
	days, hours, minutes = timeLast.days, 0, 0

	while secondsLast>SECONDS_IN_HOUR:
		hours+=1
		secondsLast-=SECONDS_IN_HOUR
	while secondsLast>SECOUND_IN_MINUTE:
		minutes+=1
		secondsLast-=SECOUND_IN_MINUTE

	resString = u""
	if days: resString+=u"%d %s "%(days, days_to_hr(days))
	if hours: resString+=u"%d %s "%(hours, hours_to_hr(hours))
	if minutes: resString+=u"%d %s"%(minutes, minutes_to_hr(minutes))
	else: resString+=u"ровно"
	return resString

#print calcTimeToTSN()